/*
 * Copyright:  2018 smarabbit studio.
 *
 *  Licensed under the Confluent Community License; you may not use this file
 *  except in compliance with the License.  You may obtain a copy of the License at
 *
 *  http://www.confluent.io/confluent-community-license
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 *  WARRANTIES OF ANY KIND, either express or implied.  See the License for the
 *  specific language governing permissions and limitations under the License.
 *
 *  @作   者： 黄开晖 (117227773@qq.com)
 *  @日   期:  2021年5月26日
 */
package com.massyframework.beanskin.runtime.framework;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;



/**
 * 支持初始化参数的配置项
 * @author huangkh
 *
 */
class InitParamConfig extends SimpleBeanRegistry {
	
	private Map<String, String> params;

	/**
	 * 
	 */
	public InitParamConfig() {
		this.params = new ConcurrentHashMap<>();
	}


	/**
	 * 获取{@code name}对应的参数
	 * @param name {@link String},参数名
	 * @return {@link String},参数值，可能返回null.
	 */
	public String getParameter(String name) {
		return this.params.get(name);
	}

	/**
	 * 所有参数名
	 * @return {@link List}
	 */
	public List<String> getParameterNames() {
		return new ArrayList<>(this.params.keySet());
	}

	
	/**
	 * 设置参数
	 * <p>
	 * 不能覆盖已有参数，参数已经存在时，直接返回false.
	 * @param name {@link String},参数名
	 * @param value {@link String},参数值
	 * @return {@link boolean},参数已经存在，则直接返回{@code false},否则返回{@code true}
	 */
	public boolean setParameter(String name, String value) {
		return this.params.putIfAbsent(name, value) == null;
	}

}
